//app.js
App({
  data: {

  },
  onLaunch: function() {
    this.getSystemInfo();
  },
  getToken: function (cb, inviteUserid, qrCodeId) {
    var token = "";
    var token = wx.getStorageSync('token');
    if (token) {
      typeof cb == "function" && cb(token);
    } else {
      var self = this;
      wx.login({
        success: res => {
          if (res.code) {
            wx.request({
              url: this.host + '/app/wechat/login',
              data: {
                code: res.code,
                inviteUserId: inviteUserid,
                qrCodeId: qrCodeId
              },
              method: 'GET',
              success: function(res) {
                var resultCode = res.data.code;
                if (resultCode == 0) {
                  wx.setStorage({
                    key: "token",
                    data: res.data.token
                  })
                  self.globalData.token = res.data.token;
                  token = res.data.token;
                  typeof cb == "function" && cb(token);
                }
              }
            })
          }

        }
      })
    }
    
  },

  getSystemInfo() {
    wx.getSystemInfo({
      success: function(res) {
        // console.log(res.windowWidth);
        // console.log(res.windowHeight);
      },
    })
  },
  globalData: {
    userInfo: null,
    token: null,
    sysInfo: {
      sysHeight: 0,
      sysWidth: 0
    }
  },
  // host: 'http://127.0.0.1:80/zyt'
  // host: 'http://192.168.0.127:80/zyt'
  // host: 'http://127.0.0.1:8080/zyt'
  host: 'http://192.168.1.66:80/zyt'
})